package com.ds.lens.data.service.dao;

import com.ds.lens.data.service.dao.entity.LensResource;
import com.ds.lens.data.service.dao.sql.provider.LensResourceSqlProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface LensResourceDao {
    @Delete({
            "delete from lens_resource",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into lens_resource (id, name, ",
            "url, type, parent_resource_id, ",
            "creator, created_time, ",
            "mender, modified_time)",
            "values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
            "#{url,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, #{parentResourceId,jdbcType=BIGINT}, ",
            "#{creator,jdbcType=VARCHAR}, #{createdTime,jdbcType=TIMESTAMP}, ",
            "#{mender,jdbcType=VARCHAR}, #{modifiedTime,jdbcType=TIMESTAMP})"
    })
    int insert(LensResource record);

    @InsertProvider(type = LensResourceSqlProvider.class, method = "insertSelective")
    int insertSelective(LensResource record);

    @Select({
            "select",
            "id, name, url, type, parent_resource_id, creator, created_time, mender, modified_time",
            "from lens_resource",
            "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "url", property = "url", jdbcType = JdbcType.VARCHAR),
            @Result(column = "type", property = "type", jdbcType = JdbcType.TINYINT),
            @Result(column = "parent_resource_id", property = "parentResourceId", jdbcType = JdbcType.BIGINT),
            @Result(column = "creator", property = "creator", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "mender", property = "mender", jdbcType = JdbcType.VARCHAR),
            @Result(column = "modified_time", property = "modifiedTime", jdbcType = JdbcType.TIMESTAMP)
    })
    LensResource selectByPrimaryKey(Long id);

    @UpdateProvider(type = LensResourceSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(LensResource record);

    @Update({
            "update lens_resource",
            "set name = #{name,jdbcType=VARCHAR},",
            "url = #{url,jdbcType=VARCHAR},",
            "type = #{type,jdbcType=TINYINT},",
            "parent_resource_id = #{parentResourceId,jdbcType=BIGINT},",
            "creator = #{creator,jdbcType=VARCHAR},",
            "created_time = #{createdTime,jdbcType=TIMESTAMP},",
            "mender = #{mender,jdbcType=VARCHAR},",
            "modified_time = #{modifiedTime,jdbcType=TIMESTAMP}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(LensResource record);
}
